package com.memorypalace.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.memorypalace.deck.biz.NoteBiz;
import com.memorypalace.deck.biz.NoteTypeBiz;
import com.memorypalace.pojo.NoteType;
import com.memorypalace.pojo.User;
import com.memorypalace.util.AJaxUtil;

@Controller
@RequestMapping("/notetype")
public class NoteTypeAction {
	

	@Autowired
	private NoteBiz noteBiz;
	@Autowired
	private NoteTypeBiz noteTypeBiz;
	
	@RequestMapping("/getmynotetype")
	@ResponseBody
	public void getMyNoteType(HttpServletRequest request,HttpServletResponse response){
		String userId = "c34487b4-35e3-11e7-8e4c-e18a12b866d4";
		User user = (User) request.getSession().getAttribute("user");
		userId = user.getUserId();
		List<NoteType> noteTypeList = noteTypeBiz.getNoteTypeByUserId(userId);
		
		AJaxUtil.sendJsonByObj(noteTypeList, response);
	}
	
	
	@RequestMapping("/getnotetypebyid")
	@ResponseBody
	public void getMyNoteType(HttpServletRequest request,HttpServletResponse response,String noteTypeId){
		String userId = "c34487b4-35e3-11e7-8e4c-e18a12b866d4";
		User user = (User) request.getSession().getAttribute("user");
		userId = user.getUserId();
		NoteType noteType = noteTypeBiz.getNoteTypeByNoteTypeId(noteTypeId);
		
		AJaxUtil.sendJsonByObj(noteType, response);
	}

	@RequestMapping("/editnotetype")
	@ResponseBody
	public void editNoteType(NoteType noteType,Map<String,Object> map){
		Boolean editFlag=noteTypeBiz.editNoteType(noteType);
		map.put("editFlag", editFlag);
	}
	
	@RequestMapping("/deletecardstyle")
	@ResponseBody
	public void deleteCardStyleById(String cardStyleId,HttpServletResponse response) {
		System.out.println("deletecardstyle:"+cardStyleId);
	}
}

